/*
 * @Author: Wang WeiHao
 * @Date: 2024-01-11 17:58:03
 * @LastEditors: Wang WeiHao
 * @LastEditTime: 2024-05-13 11:21:03
 * @Description: 
 * @FilePath: \hmcs_map\src\main.ts
 */
import { createApp } from 'vue'
import App from './App.vue'
import "./style.css";
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import './assets/main.css'
import API from '@/network/api/index'
import {Split} from 'view-ui-plus'
import 'view-ui-plus/dist/styles/viewuiplus.css'
import './assets/css/global-lu.css'
import 'ol/ol.css'
import '@/assets/font/font.css'
import "bootstrap/dist/css/bootstrap.min.css"
import "bootstrap"
import "bootstrap/dist/js/bootstrap.js"
import '@/assets/css/global_bootstrap.scss'
import * as echarts from "echarts";


import 'bootstrap-icons/font/bootstrap-icons.css';
/**
 * 引入这些方便vue进行代码
 */
import  '@/hook/index';

const app = createApp(App)

// 注册全局事件总线
app.config.globalProperties.$api = API;
// 绑定所有ico
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  // console.log(key)
  app.component(key, component)
}
app.use(store)
app.use(router)

/**
 * 引入中文 element 
 */
 app.use(ElementPlus,{locale:zhLocale})
 app.component('Split', Split);
 app.mount('#app')

//  document.title = import.meta.env.VITE_APP_TITLE as string

router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title 否则使用默认设置的值*/
    
    if (to.meta.title) {
      document.title = to.meta.title as string
    } else {
      document.title = import.meta.env.VITE_APP_TITLE as string
    }
    next()
  })


  // 定义全局组件(防止按钮连续点击)  el组件表示元素对象  binding表示绑定参数
app.directive('throttle', {
  mounted(el, binding) {
      el.addEventListener('click', () => {
          el.style.pointerEvents = 'none';
          if (!el['disable']) {
              setTimeout(() => {
                  el.style.pointerEvents = 'auto';
              }, binding.value || 2000);
          }
      });
  }
});

// 全局指令  
app.directive('dragView', {
  mounted(el, binding) {
      // 一般指针只有放在窗口的顶部才能拖动整个窗口，使用时在组件的顶部设置一个类名为dragHeader的元素
      let dragHeader = el.querySelector(".dragHeader");
      dragHeader.style.cursor = "move";
      dragHeader.onmousedown = (e: any) => {    
          var disx = e.pageX - el.offsetLeft;
          var disy = e.pageY - el.offsetTop;
          document.onmousemove =  (e)=> {
              el.style.left = e.pageX - disx + 'px';
              el.style.top = e.pageY - disy + 'px';
          }
          document.onmouseup = function () {
              document.onmousemove = null;
              document.onmouseup = null;
          }
      }
  }
});

